package cn.jiyun.leyou.goods.controller;

import cn.jiyun.leyou.goods.service.GoodsHtmlService;
import cn.jiyun.leyou.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsController {

    @Autowired
    GoodsService goodsService;
    @Autowired
    GoodsHtmlService goodsHtmlService;

    @GetMapping("{id}.html")
    public String item(@PathVariable("id")Long id, Model model){

        // 构建对应的参数信息
        Map<String,Object> map = goodsService.buildGoods(id);
        model.addAllAttributes(map);
        // 这个值最终会在html页面的两个地方用？标签中<div th:text="xxx"></div>
        // js中能使用吗？
        goodsHtmlService.toHtml(id);
        return "item";
    }

}
